﻿Namespace FTTK.Json
    Public Class JsonObject
        Inherits Dictionary(Of String, Object)

        ''' <summary>
        ''' Gets the value.
        ''' </summary>
        ''' <typeparam name="T"></typeparam>	
        ''' <param name="key">The key.</param>
        ''' <param name="defaultValue">The default value (if key not exixts).</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetValue(Of T)(key As String, Optional defaultValue As T = Nothing) As T
            Dim retVal As T = defaultValue
            If Me.ContainsKey(key) Then
                retVal = CType(Me.Item(key), T)
            End If
            Return retVal
        End Function

        ''' <summary>
        ''' Determines whether the JsonObject contains one of key in a list of string.
        ''' </summary>
        ''' <param name="keys">The keys.</param>
        ''' <returns><c>true</c> if JsonObject contains one of key; otherwise, <c>false</c>.</returns>
        ''' <remarks></remarks>
        Public Function ContainsOneOfKey(keys As IEnumerable(Of String)) As Boolean
            Dim query = From k In keys
                        Where Me.ContainsKey(k)
                        Select k

            Return query.Any()
        End Function
    End Class
End Namespace